package com.example.kingdee.schedule;

import com.example.kingdee.dto.SyncDto;
import com.example.kingdee.service.JuShuiTanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * 聚水潭和云星空销售出库对接（聚水潭销售出库->云星空销售出库）
 */
@Component
@EnableScheduling
public class SalOutSyncSchedule implements SchedulingConfigurer {

    //每1分钟执行一次
    private final String cron = "0 0/1 * * * ? ";

    @Autowired
    private JuShuiTanService juShuiTanService;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(() -> {
//            SyncDto syncDto = new SyncDto();
//            syncDto.setSyncType("销售出库同步");
//            syncDto.setStartTimeType(Calendar.HOUR);
//            syncDto.setEndTimeType(Calendar.HOUR);
//            syncDto.setStart(-6);
//            syncDto.setEnd(1);
            //处理七天内的数据
//            juShuiTanService.jstBillSync(syncDto);
        }, triggerContext -> {
            CronTrigger cronTrigger = new CronTrigger(cron);
            return cronTrigger.nextExecutionTime(triggerContext);
        });
    }
}
